package model

import (
	jsoniter "github.com/json-iterator/go"
	"time"
)

type Project struct {
	ID            uint       `gorm:"primary_key"`
	CreatedAt     time.Time  `json:"createdTime"`
	UpdatedAt     time.Time  `json:"updatedTime"`
	Name          string     `json:"name"`

	DepartmentID  uint       `json:"departmentId"`
	Department    Department `gorm:"ForeignKey:departmentId"`

	ManagerUserID uint       `json:"managerUserId"`
	User          User       `gorm:"ForeignKey:managerUserId"`
}

type CustomProject struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`

	Department struct{
		ID uint `json:"id"`
		Name string `json:"name"`
	} `json:"department"`

	User struct {
		ID uint `json:"id"`
		UserName string `json:"userName"`
	}
}

type ProjectCopy struct {
	Project
}

func (c *ProjectCopy) MarshalJSON() ([]byte, error) {
	d := CustomProject {
		ID:   c.ID,
		Name: c.Name,
	}
	d.Department.ID = c.Department.ID
	d.Department.Name = c.Department.Name

	d.User.ID = c.User.ID
	d.User.UserName = c.User.UserName

	return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(d)
}